package com.example.sp1902.fpage;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.sp1902.R;
import com.example.sp1902.goods.GoodsTypeBean;
import com.example.sp1902.utils.BaseFragment;
import com.example.sp1902.utils.URLUtils;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

import java.util.List;

public class FPHotFragment extends BaseFragment {
    TextView tv01,tv02,tv03,tv12,tv13,tv11;
    ImageView iv0,iv1;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_fphot, container, false);
        initView(view);
        connectNetwork(URLUtils.hotGoodsURL);
        return view;
    }

    private void initView(View view) {
        tv01 = view.findViewById(R.id.frag_hot_tv01);
        tv02 = view.findViewById(R.id.frag_hot_tv02);
        tv03 = view.findViewById(R.id.frag_hot_tv03);
        tv11 = view.findViewById(R.id.frag_hot_tv11);
        tv12 = view.findViewById(R.id.frag_hot_tv12);
        tv13 = view.findViewById(R.id.frag_hot_tv13);
        iv0 = view.findViewById(R.id.frag_hot_iv0);
        iv1 = view.findViewById(R.id.frag_hot_iv1);
    }

    @Override
    public void onSuccess(String result) {
        GoodsTypeBean bean = new Gson().fromJson(result, GoodsTypeBean.class);
        List<GoodsTypeBean.DataBean> list = bean.getData();
        if (list!=null&&list.size()>0) {
            GoodsTypeBean.DataBean b0 = list.get(0);
            tv01.setText(b0.getName());
            tv02.setText(b0.getInfo());
            tv03.setText("￥"+b0.getPrice()+"元");
            String pic0 = URLUtils.PUBLIC_URL+b0.getPhoto();
            Picasso.with(getContext()).load(pic0).into(iv0);

            GoodsTypeBean.DataBean b1 = list.get(1);
            tv11.setText(b1.getName());
            tv12.setText(b1.getInfo());
            tv13.setText("￥"+b1.getPrice()+"元");
            String pic1 = URLUtils.PUBLIC_URL+b1.getPhoto();
            Picasso.with(getContext()).load(pic1).into(iv1);
        }
    }
}
